<template>
  <div class="tab-control">
    <div
      v-for="(item, i) in titles"
      :key="i"
      class="item"
      :class="{ active: i === currentIndex ? 'active' : '' }"
      @click="tab(i)"
    >
      <span>{{ item }}</span>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    titles: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      currentIndex: 0,
    };
  },
  methods: {
    tab(i) {
      this.currentIndex = i;
      this.$emit("tabClick", i);
    },
  },
};
</script>

<style lang="less" scoped>
.tab-control {
  display: flex;
  font-size: 16px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  background-color: #fff;
  .item {
    flex: 1;
  }
  .active {
    color: var(--color-high-text);
    span {
      padding: 3px;
      border-bottom: 4px solid var(--color-high-text);
    }
  }
}
</style>
